const fs = require('fs')
const path = require('path')
const exec = require('child_process').execSync
function resolvePath (dir) {
	return path.join(__dirname, dir)
}
const hasCommitizen = function () {
	const npmRoot = exec('npm root -g')
	const npmRootPath = npmRoot.toString('utf8').trim()
	return fs.existsSync(`${npmRootPath}/commitizen`)
}
const hasCommitMsg = function () {
	const _path = resolvePath('../node_modules/cz-customizable')
	return fs.existsSync(_path)
}

const validateProxy = async function () {
	if (!hasCommitizen()) {
		console.log('请先执行 npm install -g commitizen')
		process.exit(1)
	}
	if (!hasCommitMsg()) {
		console.log('存在没有安装的依赖, 请重新执行npm install')
		process.exit(1)
	}
}
validateProxy()
